
<center>
    <h3>请选择图片文件：JPG/GIF</h3>
    <form name="form" id="form" action="faceUpload" method="post" enctype="multipart/form-data">
    <input type="file" name="file" id="file" multiple="multiple"/>
        <input type="submit" value="上传图片">
        <br>
        <img src="" class="img-thumbnail" id="img" style="width: 25%; height: auto; display: none;">
    </form>
</center>

<script>
    $("#file").change(function(){
        var objUrl = getObjectURL(this.files[0]) ;
        console.log("objUrl = "+objUrl) ;
        if (objUrl) {
            $("#img").attr("src", objUrl) ;
        }
        $("#img").css('display','block');
    }) ;
    //建立一個可存取到該file的url
    function getObjectURL(file) {
        var url = null ;
        if (window.createObjectURL!=undefined) { // basic
            url = window.createObjectURL(file) ;
        } else if (window.URL!=undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file) ;
        } else if (window.webkitURL!=undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file) ;
        }
        return url ;
    }
</script>
